package cn.com.joco.cf.core.cui.dataTable;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public class DataTableResponse<E> {
	
	long iTotalDisplayRecords=0l;   //记录总数
	String sEcho="";              //从DataTableRequest中接收到的值，原样返回，用于判断数据的安全性，
	List<E> aaData=new ArrayList<E>();  //里面放置的是Map，每个Map即为一条数据记录
	
	public long getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}
	public void setiTotalDisplayRecords(long iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}
	
	public  List<E> getAaData() {
		return aaData;
	}
	public void setAaData(List<E> aaData) {
		this.aaData = aaData;
	}
	public String getsEcho() {
		return sEcho;
	}
	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}
	public static <T> DataTableResponse<T> build(Page<T> pageable,DataTableRequest request){
		DataTableResponse<T> dResponse = new DataTableResponse<T>();
		dResponse.setAaData(pageable.getContent());
		dResponse.setiTotalDisplayRecords(pageable.getTotalElements());
		dResponse.setsEcho(request.getsEcho());	
	   return dResponse;
	}
	
	
}
